﻿using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Xsl;
using Ext.Net;

/// <summary>
/// 2011.11.08 박승한 - Ext컨트롤 이용 베스트 싸이트 작성
/// </summary>
public partial class Popup_People_Add : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SetCombo();

            if (!string.IsNullOrEmpty(Request.QueryString["code"]))
            {
                SetPeople();
            }
        }

        if (!X.IsAjaxRequest)
        {
            //분석 요
            string text = @"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed metus nibh, sodales a, porta at, vulputate eget, dui. Pellentesque ut nisl. Maecenas tortor turpis, interdum non, sodales non, iaculis ac, lacus. Vestibulum auctor, tortor quis iaculis malesuada, libero lectus bibendum purus, sit amet tincidunt quam turpis vel lacus. In pellentesque nisl non sem. Suspendisse nunc sem, pretium eget, cursus a, fringilla vel, urna.";

            this.ResourceManager1.RegisterClientScriptBlock("text", string.Format("var text=\"{0}\";", text));

            foreach (Portlet portlet in Ext.Net.Utilities.ControlUtils.FindControls<Portlet>(this.Page))
            {
                if (!portlet.ID.Equals("Portlet1"))
                {
                    portlet.Html = "={text}";
                    portlet.Padding = 5;
                }
            }
            
        }

    }


    protected void btnSave_Click(object sender, DirectEventArgs e)
    {
        SavePeople();
    }


    protected void SavePeople()
    {
        try
        {
            using (EmdisBest.WebService.Service oService = new EmdisBest.WebService.Service())
            {
                int iResult;
                if (string.IsNullOrEmpty(Request.QueryString["code"]))
                {
                    iResult = oService.INSERT_D_PA100T_MASTER_I(this.tbxName.Text, this.tbxJumin.Text, this.cbxWork.SelectedItem.Value, this.tbxAddr.Text
                                                                  , this.tbxTel.Text, this.tbxMobile.Text, this.tbxBank.Text, this.tbxAccount.Text, int.Parse(this.tbxPay.Text)
                                                                  , "", 0, 0, "", "", this.cbxTeam.SelectedItem.Value);
                }
                else
                {
                    iResult = oService.UPDATE_D_PA100T_MASTER_U(Request.QueryString["code"], this.tbxName.Text, this.tbxJumin.Text, this.cbxWork.SelectedItem.Value, this.tbxAddr.Text
                                                                  , this.tbxTel.Text, this.tbxMobile.Text, this.tbxBank.Text, this.tbxAccount.Text, int.Parse(this.tbxPay.Text)
                                                                  , "", 0, 0, "", "", this.cbxTeam.SelectedItem.Value);
                }
            }
        }
        catch (Exception ex)
        {
            ex.ToString();
        }
    }


    private void SetCombo()
    {
        try
        {
            using (EmdisBest.WebService.Service oService = new EmdisBest.WebService.Service())
            {
                DataSet ds = oService.Select_DDDW_GROUPNM_ALL_S();

                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    ds.Tables[0].Rows[0].Delete();

                    this.StrCbx.DataSource = ds;
                    this.StrCbx.DataBind();


                    this.cbxTeam.SelectedIndex = 0;
                }


                ds = oService.Select_DDDWCLASS_NM_S();

                this.Store3.DataSource = ds;
                this.Store3.DataBind();

                if (ds != null && ds.Tables[0].Rows.Count > 0)
                {
                    this.cbxWork.SelectedIndex = 0;
                }
            }
        }
        catch (Exception ex)
        {
            ex.ToString();
        }
    }



    private void SetPeople()
    {
        try
        {
            using (EmdisBest.WebService.Service oService = new EmdisBest.WebService.Service())
            {
                DataSet ds = oService.Select_D_PA100T_MASTER_S(Request.QueryString["code"]);

                this.tbxName.Text = ds.Tables[0].Rows[0]["NAME"].ToString();
                this.cbxTeam.Value = ds.Tables[0].Rows[0]["GROUP_CD"];
                this.tbxJumin.Text = ds.Tables[0].Rows[0]["JUMIN_NO"].ToString();
                this.cbxWork.Value = ds.Tables[0].Rows[0]["CLASS"];
                this.tbxPay.Text = ds.Tables[0].Rows[0]["PAY"].ToString();
                this.tbxAddr.Text = ds.Tables[0].Rows[0]["ADDRESS"].ToString();
                this.tbxTel.Text = ds.Tables[0].Rows[0]["TEL"].ToString();
                this.tbxMobile.Text = ds.Tables[0].Rows[0]["HP"].ToString();
                this.tbxBank.Text = ds.Tables[0].Rows[0]["BANK"].ToString();
                this.tbxAccount.Text = ds.Tables[0].Rows[0]["ACCOUNT_NO"].ToString();
            }
        }
        catch (Exception ex)
        {
            ex.ToString();
        }
    }

    
}
